package processer

import (
	"communication-system/common/messages"
	"communication-system/common/utils"
	"encoding/json"
	"fmt"
	"net"
)

type SmsProcess struct {
}

//写转发消息的方法
func (smsprocess *SmsProcess) SendGroupMes(mes *messages.Message) {

	//将client发送过来的消息接收，处理
	var smsMes messages.SmsMes
	err := json.Unmarshal([]byte(mes.Data), &smsMes)
	if err != nil {
		fmt.Println("处理client发送的消息失败..", err)
		return
	}
	data, _ := json.Marshal(mes)
	for id, up := range usermger.onlineusers {

		if id == smsMes.UserId {
			continue

		}
		smsprocess.SendMesToEther(data,up.Conn)

	}

}

func (smsprocess *SmsProcess)SendMesToEther(data []byte, conn net.Conn) {
	//发送消息
	tf :=&utils.TransFer{
		Conn: conn,
	}
	err :=tf.WritePkg(data)
	if err != nil {
		fmt.Println("转发消息失败...",err)
		return
	}


}
